﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Worktool
{
    public partial class Stammdaten : Form
    {
        public Stammdaten()
        {
            InitializeComponent();
            this.Text = "Stammdaten: " + Properties.Settings.Default.CurrentDBName; 
            this.dataGridView1.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellValueChanged);

        }

        private void Stammdaten_Load(object sender, EventArgs e)
        {
            this.vw_std_engineeringTableAdapter.updateStammdatenUsed();
            this.vw_std_engineeringTableAdapter.updateStammdatenExtended();
            this.vw_std_engineeringTableAdapter.Fill(this.aSCDataSet.vw_std_engineering);
            this.vw_std_manufacturerTableAdapter.Fill(this.aSCDataSet.vw_std_manufacturer);
            label2.Text = dataGridView1.RowCount.ToString();
            comboBox1.Text = "";
            this.vwstdengineeringBindingSource.Filter = string.Format("Manufacturer LIKE '{0}'", (comboBox1.Text + "*"));           
            
        }

        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != dataGridView1.Columns["updateDate"].Index || e.ColumnIndex != dataGridView1.Columns["updateUser"].Index)
            {
                try
                {
                    dataGridView1.CurrentRow.Cells["updateDate"].Value = DateTime.Today;
                    dataGridView1.CurrentRow.Cells["updateUser"].Value = Properties.Settings.Default.User;
                    this.vwstdengineeringBindingSource.EndEdit();
                    vw_std_engineeringTableAdapter.Update(aSCDataSet);
                }
                catch (Exception ex)
                {
                }
            }
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            this.vwstdengineeringBindingSource.Filter = string.Format("Manufacturer LIKE '{0}'", (comboBox1.Text + "*"));
            label2.Text = dataGridView1.RowCount.ToString();
        }
    }
}
